/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.server.database.engine.ddl.field.mapping;

import com.snail.server.database.engine.ddl.field.annotation.ToFieldType;
import com.snail.server.database.engine.ddl.field.dto.FieldAddDTO;
import com.snail.server.database.engine.ddl.field.entity.Field;
import com.snail.server.database.engine.ddl.field.enums.FieldTypeEnum;
import com.snail.server.database.engine.ddl.field.vo.FieldVO;
import com.snail.starter.db.annotation.mapstruct.ToYesOrNo;
import com.snail.starter.db.enums.YesOrNoEnum;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zgadmin
 * @date 2025/9/9 14:53
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = {YesOrNoEnum.class, FieldTypeEnum.class})
public interface FieldMapping {

    @Mapping(source = "fieldAddDTO.type", target = "type", qualifiedBy = ToFieldType.class)
    @Mapping(source = "fieldAddDTO.notNull", target = "notNull", qualifiedBy = ToYesOrNo.class)
    @Mapping(source = "fieldAddDTO.primaryKey", target = "primaryKey", qualifiedBy = ToYesOrNo.class)
    @Mapping(target = "status", expression = "java(com.snail.starter.db.enums.EnableOrDisEnableEnum.ENABLE)")
    @Mapping(target = "tableId", source = "tableId")
    Field fieldAddDTO2Field(Long tableId, FieldAddDTO fieldAddDTO);

    ArrayList<Field> batchFieldAddDTO2Field(Long tableId, List<FieldAddDTO> fieldAddList);

    @Mapping(target = "type", expression = "java(field.getType().getValue())")
    @Mapping(target = "notNull", expression = "java(field.getNotNull().getBoolean())")
    @Mapping(target = "primaryKey", expression = "java(field.getPrimaryKey().getBoolean())")
    @Mapping(target = "status", expression = "java(field.getStatus().getValue())")
    FieldVO toFieldVO(Field field);

}